#include <iostream>

class MyException
{
public:
    MyException()
    {
        std::cout<<"异常对象构造"<<std::endl;
    }
    MyException(const MyException& e)  
    {
        std::cout<<"拷贝对象构造"<<std::endl;
    }
    ~MyException()
    {
        std::cout<<"异常对象析构"<<std::endl;
    }
    
};

void func()
{
    throw MyException();
}

int main()
{
    try
    {
        func();
    }
    //当异常捕获有多个可匹配时,会优先匹配前面的
    catch(MyException e)
    {
        std::cerr << "捕获MyException e\n";
    }

    catch(MyException& e)
    {
        std::cerr << "捕获MyException& e\n";
    }

    catch(MyException *e)
    {
        std::cerr << "捕获MyException* e\n";
        //堆上指针手动放
        delete e;
    }
    

    std::cout<<"hello world"<<std::endl;
    return 0;
}